﻿using System;

namespace ControlExplorer.samples.VirtualScrollPaging
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack)
      {
        return;
      }

      InitSpread(FpSpread1, FpSpread1.Sheets[0]);
      this.FpSpread1.UseClipboard = false;
    }

    private void InitSpread(FarPoint.Web.Spread.FpSpread spread, FarPoint.Web.Spread.SheetView sheet)
    {
      int i = 0;
      spread.UseClipboard = false;
      spread.CssClass = "spreadStyle";

      spread.Pager.Mode = FarPoint.Web.Spread.PagerMode.Both;
      spread.Pager.Position = FarPoint.Web.Spread.PagerPosition.TopCommandBar;

      FarPoint.Web.Spread.Model.DefaultSheetDataModel datamodel = (FarPoint.Web.Spread.Model.DefaultSheetDataModel)sheet.DataModel;
      datamodel.RowCount = 2000;

      for (i = 0; i <= datamodel.RowCount - 1; i++)
      {
        datamodel.SetValue(i, 0, i + 1);
      }

      sheet.AllowVirtualScrollPaging = true;
      sheet.PageSize = 15;

      ApplyCustomSettings(sheet);
    }

    void ApplyCustomSettings(FarPoint.Web.Spread.SheetView sheet)
    {
      sheet.VirtualScrollPagingPrevRowCount = int.Parse(PreviousRowsDropDownList.SelectedValue);
      sheet.ScrollingContentVisible = ShowTipCheckBox.Checked;
      if (PagingTipFormatDropDownList.SelectedIndex == 0) sheet.VirtualScrollPagingFormatString = "Page {page} of {count}";
      else if (PagingTipFormatDropDownList.SelectedIndex == 3) sheet.VirtualScrollPagingFormatString = " ";
      else sheet.VirtualScrollPagingFormatString = PagingTipFormatDropDownList.SelectedValue;
    }

    protected void ApplyButton_Click(object sender, EventArgs e)
    {
      ApplyCustomSettings(FpSpread1.Sheets[0]);
    }
  }
}